/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.clbs.ex.springgwt.server.service;

import com.clbs.ex.springgwt.client.model.Issue;
import com.clbs.ex.springgwt.client.model.IssueStatus;
import com.clbs.ex.springgwt.client.service.IssueTrackerService;
import com.clbs.ex.springgwt.server.dao.IssueDAO;
import com.clbs.ex.springgwt.server.dao.IssueStatusDAO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author peerawat.poombua
 */

public class IssueTrackerServiceImpl implements IssueTrackerService {

    @Autowired
    private IssueDAO issueDAO;

    @Autowired
    private IssueStatusDAO issueStatusDAO;

    public void createIssue(Issue issue) {
        issueDAO.createIssue(issue);
    }

    public Issue getIssue(int issueID) {
       return issueDAO.getIssue(issueID);
    }

    public boolean deleteIssue(int issueID) {
        return issueDAO.deleteIssue(issueID);
    }

    public List<Issue> getAllIssues() {
        List<Issue> issues = issueDAO.getAllIssues();
        for (int index = 0; index < issues.size(); index++) {
            IssueStatus issueStatus = issueStatusDAO.getIssueStatus(issues.get(index).getIssue_statusID());
            issues.get(index).setIssueStatus(issueStatus);
        }
        return issues;
    }
}
